define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'vppz/kangyang_service_orders/index' + location.search,
                    //add_url: 'vppz/order/add',
                    //edit_url: 'vppz/order/edit',
                    //del_url: 'vppz/order/del',
                    multi_url: 'vppz/kangyang_service_orders/multi',
                    import_url: 'vppz/kangyang_service_orders/import',
                    table: 'vppz_service_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                //fixedColumns: true,
                //fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: 'ID',searchable:false},
						{field: 'order_no', title: '订单号', operate: 'LIKE'},
						{field: 'user.avatar_url', title: '用户', operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image,searchable:false},
						{field: 'user.nickname', title: '用户昵称', operate: 'LIKE'},
						{field: 'customer_name', title: '联系人', operate: 'LIKE'},
						{field: 'customer_phone', title: '联系电话', operate: 'LIKE'},

						{field: 'package_name', title: '套餐名称', operate: 'LIKE'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN',visible: false,searchable:false},


						{field: 'order_status', title: __('Status'), searchList: {"0":'待支付',"1":'已支付',"4":'已取消'}, formatter: Table.api.formatter.status,custom:{'0':'warning','4':'info','1':'success'}},//"0":__('Status 0'),

						{field: 'community.name', title: '社区医院', operate: 'LIKE'},
						{field: 'community.province', title: '省', operate: 'LIKE'},
						{field: 'community.city', title: '市', operate: 'LIKE'},
						{field: 'community.district', title: '区县', operate: 'LIKE'},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
						{field: 'payment_time', title: '支付时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [{
                                    name: 'detail',
                                    title: '订单明细',
									text: '订单明细',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'vppz/kangyang_service_orders/detail'
                                },{
                                    name: 'genjin',
                                    title: '订单跟进',
									text: '订单跟进',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'vppz/followup/index'
                                }],
                                formatter: function (value, row, index) { //隐藏自定义的视频按钮
                                    var that = $.extend({}, this);
                                    var table = $(that.table).clone(true);

                                    //权限判断
                                   if(row.order_status !== 1){ //通过Config.chapter 获取后台存的chapter
                                        $(table).data("operate-genjin", null);
                                    }
                                   that.table = table;
                                    return Table.api.formatter.operate.call(that, value, row, index);
                                }
						}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
